<!DOCTYPE html>
<html lang="en" class="no-js" xmlns:th="http://www.thymeleaf.org"
	xmlns:layout="http://www.ultraq.net.nz/web/thymeleaf/layout"
	layout:decorator="admin/layout">
<head>
<title>会员管理</title>
<script th:inline="javascript">
	/*<![CDATA[*/
	$.validator.addMethod('typeAllowed', function(value, element) {
		var suffix = value.split('.').pop().toLowerCase();
		if (!(suffix.match(/jpg|jpeg|png|gif/i))) {
			return false;
		} else {
			return true;
		}
	}, '上传的图片类型只能是png,gif,jpg,jpeg');
	function uploadFile(e) {
		$('#imgFile').click();
	}

	function uploadFile2(e) {
		if ($(e).val() != null) {
			var filename = $(e).val().substr($(e).val().lastIndexOf('\\') + 1);
			if (!($(e).val().split('.').pop().toLowerCase()
					.match(/jpg|jpeg|png|gif/i))) {
				$('#file_upload_help').show();
				return false;
			} else {
				$('#file_upload_help').hide();
			}
			$('#file_upload_span').html(filename);
			$('#form_brand_image').submit();
		}
	}
	$()
			.ready(
					function() {
						$('#iframe_brand_image')
								.load(
										function() {
											var data = $(
													window.frames['iframe_brand_image'].document.body)
													.html();
											if (data != null
													&& data != ''
													&& !data
															.match('You failed to upload')) {
												$('#brand_logo_display_div')
														.html(
																'<img style="width:100%;height:100%;" src="'
																		+ $
																				.parseJSON(data).url
																		+ '"></img>');
												$('#logo').attr("value",
														$.parseJSON(data).url);
											}
										});
					})
			/*]]>*/
</script>
</head>
<body>
	<div layout:fragment="content">
		<div class="row">
			<div class="col-md-12">
				<div class="btn-group pull-right">
					<a href="index.html" th:href="@{/admin/user/user/index/}"
						id="sample_editable_1_new" class="btn green">返回<i
						class="fa fa-arrow-circle-o-left"></i></a>
				</div>
			</div>
		</div>
		<div class="row">
			<div class="col-md-12">
				<div class="form">
					<form role="form" th:action="@{admin/user/user/save}" th:object="${user}"
						id="userForm" method="post" class="form-horizontal">
						<h4 class="form-section">会员信息</h4>
						<input type="hidden" th:field="*{id}" />
						<div class="form-body">
							<div class="form-group"
								th:class="${#fields.hasErrors('userID')}? 'form-group has-error' : 'form-group'">
								<label class="control-label col-md-3">用户ID:<span
									class="required" aria-required="true">* </span></label>
								<div class="col-md-4">
									<input type="text" class="form-control" placeholder="用户ID"
										th:field="*{userID}" />
								</div>
							</div>
							<div class="form-group"
								th:class="${#fields.hasErrors('email')}? 'form-group has-error' : 'form-group'">
								<label class="control-label col-md-3">用户E—mail:<span
									class="required" aria-required="true">* </span></label>
								<div class="col-md-4">
									<input type="text" class="form-control" placeholder="邮箱"
										th:field="*{email}" />
								</div>
							</div>
							<div class="form-group"
								th:class="${#fields.hasErrors('password')}? 'form-group has-error' : 'form-group'">
								<label class="control-label col-md-3">密码:<span
									class="required" aria-required="true">* </span></label>
								<div class="col-md-4">
									<input type="text" class="form-control" placeholder="密码"
										th:field="*{password}" />
								</div>
							</div>

							<div class="form-group">
								<label class="control-label col-md-3">是否为会员:</label>
								<div class="col-md-4">
									<div class="radio-list">
										<label class="radio-inline"> <span> <input
												id="radio_displayed_1" type="radio" value="1" checked=""
												th:field="*{isVip}" />
										</span>是
										</label> <label class="radio-inline"><span><input
												id="radio_displayed_2" type="radio" value="0"
												th:field="*{isVip}" /></span> 否</label>
									</div>
								</div>
							</div>

							<div class="form-group">
								<label class="control-label col-md-3">注册时间:<span
									class="required" aria-required="true">* </span></label>
								<div class="col-md-4">
									<span class="form-control" th:text="*{createdDate}"></span>
								</div>
							</div>
							<div class="form-group">
								<label class="control-label col-md-3">最后登录时间:<span
									class="required" aria-required="true">* </span></label>
								<div class="col-md-4">
									<span class="form-control" th:text="*{lastTime}"></span>
								</div>
							</div>
							<div class="form-group">
								<label class="control-label col-md-3">头像：</label>
								<div class="col-md-7">
									<input type="hidden" id="logo" th:field="*{headPic}" />
									<div class="form-control" style="padding: 0;">
										<span style="padding-left: 5px;" id="file_upload_span"
											name="file_upload_span">未选择文件</span><input type="button"
											class="btn blue pull-right" onclick="uploadFile(this)"
											value="浏览" />
									</div>
									<div class="form-body" id="brand_logo_display_div">
										<img id="brand_logo_display" name="brand_logo_display" style="width:15%;height:15%;"  th:if="${user.headPic != null}" th:src="${user.headPic}"/>
									</div>
									<p class="help-block text-center"
										style="color: red; display: none;" id="file_upload_help">上传的图片类型只能是png,gif,jpg,jpeg</p>
								</div>
							</div>
							<div class="form-group"
								th:class="${#fields.hasErrors('coin')}? 'form-group has-error' : 'form-group'">
								<label class="control-label col-md-3">用户金币:<span
									class="required" aria-required="true">* </span></label>
								<div class="col-md-4">
									<input type="text" class="form-control" placeholder="用户金币"
										th:field="*{coin}" />
								</div>
							</div>
							<div class="form-group"
								th:class="${#fields.hasErrors('coinBank')}? 'form-group has-error' : 'form-group'">
								<label class="control-label col-md-3">金币银行:<span
									class="required" aria-required="true">* </span></label>
								<div class="col-md-4">
									<input type="text" class="form-control" placeholder="金币银行"
										th:field="*{coinBank}" />
								</div>
							</div>
							<div class="form-group"
								th:class="${#fields.hasErrors('experience')}? 'form-group has-error' : 'form-group'">
								<label class="control-label col-md-3">用户经验:<span
									class="required" aria-required="true">* </span></label>
								<div class="col-md-4">
									<input type="text" class="form-control" placeholder="用户经验"
										th:field="*{experience}" />
								</div>
							</div>

						</div>
						<div class="form-actions fluid">
							<div class="col-md-offset-3 col-md-9">
								<button type="submit" class="btn blue" name="sub">提交</button>
							</div>
						</div>
					</form>
				</div>
			</div>

			<div style="display: none;">
				<form target="iframe_brand_image" action="/upload/USER"
					enctype="multipart/form-data" method="post" id="form_brand_image"
					name="form_brand_image">
					<input type="file" id="imgFile" onchange="uploadFile2(this)"
						name="imgFile" />
				</form>
			</div>
			<iframe style="display: none;" id="iframe_brand_image"
				name="iframe_brand_image" frameborder="0"></iframe>
		</div>
	</div>
</body>
</html>